-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add upvote and downvote function #112
Conversation
src/base/constants/types.cairo
Outdated
@@ -56,7 +56,9 @@ pub struct Publication { | |||
content_URI: ByteArray, | |||
pub_Type: PublicationType, | |||
root_profile_address: ContractAddress, | |||
root_pub_id: u256 | |||
root_pub_id: u256, | |||
upvote: Upvote, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upvote and downvote should be represented by a u256, and should increase by 1 for each upvote or downvote
@@ -146,3 +146,23 @@ pub struct QuoteParams { | |||
pointed_pub_id: u256, | |||
reference_pub_type: PublicationType | |||
} | |||
#[derive(Debug, Drop, Serde, starknet::Store, Clone)] | |||
pub struct Upvote { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these were meant to be the emitted events on upvote
block_timestamp: u64, | ||
} | ||
#[derive(Debug, Drop, Serde, starknet::Store, Clone)] | ||
pub struct Downvote { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was meant to be the emitted event on downvote
src/publication/publication.cairo
Outdated
let publication = self.get_publication(profile_address, pub_id); | ||
let caller = get_caller_address(); | ||
let has_upvoted = self.vote_status.read((caller, pub_id)); | ||
let mut vote_current_count = self.vote_count.read(pub_id) + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's not store upvotes in storage. rather simply increment the upvote item within the Publication struct, and you can always just retrieve that
src/publication/publication.cairo
Outdated
@@ -66,13 +71,18 @@ pub mod PublicationComponent { | |||
} | |||
|
|||
#[derive(Drop, starknet::Event)] | |||
pub struct QuoteCreated { | |||
quoteParams: QuoteParams, | |||
pub struct UpvoteCreated { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename event to Upvoted
src/publication/publication.cairo
Outdated
publication_id: u256, | ||
transaction_executor: ContractAddress, | ||
block_timestamp: u64, | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
pub struct DownvoteCreated { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename event to Downvoted
src/publication/publication.cairo
Outdated
@@ -266,7 +338,24 @@ pub mod PublicationComponent { | |||
) -> PublicationType { | |||
self._get_publication_type(profile_address, pub_id_assigned) | |||
} | |||
/// @notice retrieves a post vote_count | |||
/// @param pub_id the ID of the publication whose count is to be retrieved | |||
fn get_vote_count(self: @ComponentState<TContractState>, pub_id: u256) -> u256 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's have two functions to retrieve both the upvote and downvote counts. This should simply just return the value of the upvote and downvote struct items in the publication struct
No description provided.